import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * @author cy
 * @date 2024/5/31
 */
public class ShuJuChuli1 {
    public static void main(String[] args) {
        File file = new File("doc");
        File[] files = file.listFiles();
        int count = 1;
        for (File file1 : files) {
            System.out.println(file1.getName());
            if (!file1.getName().endsWith(".xlsx")) {
                continue;
            }
            ExcelReader reader = ExcelUtil.getReader(file1);
            List<Map<String, Object>> maps = reader.readAll();
            reader.close();
            for (Map<String, Object> map : maps) {
                JSONObject entries = JSONUtil.parseObj(map);
                if ("否".equals(entries.getStr("是否集采"))) {
                    Float aDouble = entries.getFloat("单 价");
                    Float aDouble1 = entries.getFloat("标准价");
                    int i = aDouble.compareTo(aDouble1);
                    if (i < 0) {
                        float v = aDouble - (aDouble1 * (1 - entries.getFloat("标准费率")));
                        map.put("营销费用", v);
                    }
                    if (i > 0) {
                        float v = (aDouble - aDouble1) * 0.87f * entries.getFloat("标准费率") + aDouble1 * entries.getFloat("标准费率");
                        map.put("营销费用", v);
                    }
                    if (i == 0) {
                        float v = aDouble1 * entries.getFloat("标准费率");
                        map.put("营销费用", v);
                    }
                }

                if ("是".equals(entries.getStr("是否集采"))) {
                    Float aDouble = entries.getFloat("单 价");
                    Float aDouble1 = entries.getFloat("标准价");
                    if (entries.getFloat("标准费率").compareTo(0.3f) < 0) {
                        float v = (aDouble - aDouble1) * 0.6f + aDouble1 * entries.getFloat("标准费率");
                        map.put("营销费用", v);
                    }

                    if (entries.getFloat("标准费率").compareTo(0.3f) >= 0) {
                        int i = aDouble.compareTo(aDouble1);
                        if (i < 0) {
                            float v = aDouble - (aDouble1 * (1 - entries.getFloat("标准费率")));
                            map.put("营销费用", v);
                        }
                        if (i > 0) {
                            float v = (aDouble - aDouble1) * 0.87f * entries.getFloat("标准费率") + aDouble1 * entries.getFloat("标准费率");
                            map.put("营销费用", v);
                        }
                        if (i == 0) {
                            float v = aDouble1 * entries.getFloat("标准费率");
                            map.put("营销费用", v);
                        }
                    }
                }
                System.out.println(JSONUtil.toJsonStr(map));
            }
            File file2 = new File(StrUtil.subBefore(file1.getName(),".",true) + count++ + ".xlsx");
            ExcelWriter writer = ExcelUtil.getWriter(file2);
            writer.write(maps);
            writer.flush();
            writer.close();
        }

    }
}
